#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int t;
ll s,a,b,c;
int main(void){
    scanf("%d",&t);
    while(t--){
        scanf("%lld%lld%lld%lld",&s,&a,&b,&c);
        ll num=s/c;
        ll add=num/a*b;
        printf("%lld\n",num+add);
    }
    return 0;
}